<%@page import="java.util.ArrayList"%>
<%@page import="com.teach.entity.user"%>
<%@page import="java.util.function.Supplier"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.List"%>
<%@ page language="java" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>用户列表</title>
		
    <base href="${pageContext.request.contextPath }/"/>
		 <link rel="stylesheet" type="text/css" href="assets/css/admin.css" />
    <script src="assets/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="assets/js/popper.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="assets/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="assets/js/sys.js" type="text/javascript" charset="utf-8"></script>
	</head>
	
	
	<body>
		<nav class="navbar navbar-expand-lg navbar-dark bg-primary fixed-top">
		 <a class="navbar-brand" href="admin/">用户列表</a>
		 
		<div class="collapse navbar-collapse" id="navbarColor02">
        <ul class="navbar-nav ml-auto">

          <li class="nav-item mr-5">
           
          </li>
          <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
              超级管理员:风清扬(admin)
            </a>
            <div class="dropdown-menu dropdown-menu-right">
              <a class="dropdown-item" href="#">修改个人信息</a>
              <a class="dropdown-item" href="#">修改登录密码</a>
              <div class="dropdown-divider"></div>
              <a class="dropdown-item _exit" href="javascript:void(0);">安全退出</a>
            </div>
          </li>
        </ul>
      </div>
    </nav>
    
    
    <nav class="left">
      <ul class="my-menu">
        <li>
          <div>系统中心</div>
          <ul>
            <li><a href="admin/user/page.jsp">用户管理</a></li>

            <li><a href="admin/config.jsp">系统设置</a></li>
            <li><a href="admin/pay-config.jsp">支付设置</a></li>
            <li><a href="admin/file-config.jsp">文件服务设置</a></li>
          </ul>
        </li>
        <li>
          <div>内容管理</div>
          <ul>
            <li><a href="admin/article/page.jsp">新闻中心</a></li>
            <li><a href="admin/article/type/page.jsp">新闻类别管理</a></li>
            <li><a href="admin/article/page-modify.jsp">单一页面管理</a></li>
          </ul>
        </li>
        <li>
          <div>产品中心</div>
          <ul>
            <li><a href="admin/mall-product/page.jsp">产品管理</a></li>
            <li><a href="admin/order/page.jsp">订单管理</a></li>
          </ul>
        </li>
        <li>
          <div>网站管理</div>
          <ul>
            <li><a href="admin/comment/page.jsp">评论管理</a></li>
            <li><a href="admin/link/page.jsp">链接管理</a></li>
          </ul>
        </li>
      </ul>
      <script type="text/javascript">
        $(function() {
          var index = 1;
          $(".my-menu>li:not(:nth-child(" + index + "))>ul").hide();
          $(".my-menu>li>div").click(function() {
            var $this = $(this);
            if ($this.next().is(":hidden")) {
              $this.parent().parent().children().children("ul:visible").hide();
              $this.next().show();
            }
          });
        });
      </script>
    </nav>
    
    
     <section>
     	 <form class="form-inline" action="user-select-bystring.let">
        <div class="form-group mx-sm-1 mb-2">
          <label class="sr-only">新闻类别：</label>
          <select class="form-control">
            <option value="">全部</option>
          </select>、
          
        </div>
        
        <div class="form-group mx-sm-1 mb-2">
          <label class="sr-only">关键字：</label>
          <input type="text" class="form-control" name="selectbystring" value="" placeholder="搜索关键字"/>
        </div>
        <button type="submit" class="btn btn-primary mb-2"><i class="fa fa-search"></i></button>
        <a href="admin/user-add.jsp" class="btn btn-success ml-auto mr-2"><i class="fa fa-plus"></i></a>
        
      </form>
      
      <table class="table table-striped">
  <thead>
    <tr>
      <th scope="col">#</th>
      <th scope="col">名字</th>
      <th scope="col">性别</th>
      <th scope="col">电话</th>
      <th scope="col">出生日期</th>
      <th scope="col">昵称</th>
      <th scope="col">账号</th>
      <th scope="col">注册日期</th>
      <th scope="col">操作</th>
    </tr>
  </thead>
  <tbody>
  
  <%
     List<user> list=(List<user>)request.getAttribute("list");
     for(int i=0;i<list.size();i++) {
    	 user u=list.get(i);

    	 pageContext.setAttribute("u", u);
   	  pageContext.setAttribute("i", i);
  %>
  
    <tr>
     <th scope="row">${i+1 }</th>
      <td>${u.name }</td>
      <td>${u.sex }</td>
      <td>${u.phone}</td>
      <td>${u.birthday}</td>
      <td>${u.nickname}</td>
      <td>${u.account_number}</td>
      <td>${u.create_time}</td>
      <td><div class="dropdown">
  <button class="btn btn-outline-primary btn-block dropdown-toggle" type="button" data-toggle="dropdown">
    操作
  </button>
  <div class="dropdown-menu dropdown-menu-right">
    <a class="dropdown-item"  href="user-find.let?userId=${u.id}">查看</a>
    <a class="dropdown-item" href="user-update-form.let?userId=${u.id}">修改</a>
    <a class="dropdown-item  _delete" href="user-delete.let?userId=${u.id}">删除</a>
  </div>
</div>
</td>
    </tr>
    
    <%} %>
    
  </tbody>
</table>
<nav aria-label="Page navigation example">
  <ul class="pagination">
    <li class="page-item">
      <a class="page-link" href="#" aria-label="Previous">
        <span aria-hidden="true">&laquo;</span>
      </a>
    </li>
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item"><a class="page-link" href="#">2</a></li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item">
      <a class="page-link" href="#" aria-label="Next">
        <span aria-hidden="true">&raquo;</span>
      </a>
    </li>
  </ul>
</nav>
     </section>
     
     
   <div class="modal fade" id="confirmDialog" tabindex="-1">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">确认对话框</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        您确定要删除这条记录吗？
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
        <a href="#" class="btn btn-primary">确定</a>
      </div>
    </div>
  </div>
</div>
    


	</body>
</html>

<script type="text/javascript">
	
$("._delete").on("click",function(){
	let $this = $(this);
	sys.confirm("您需要删除这条记录吗？",function(ret){
		if(ret){
			location = $this.attr("href");
		}
	});
	return false;
});

</script>

<%!
	//private  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
private ThreadLocal<SimpleDateFormat> format = ThreadLocal.withInitial(new Supplier<SimpleDateFormat>(){
	public SimpleDateFormat get(){
		return new SimpleDateFormat("yyyy-MM-dd");
	}
});

private String format(Date date){
	if(date==null){
		return "-";
	} else {
		return format.get().format(date);
	}
}

private ThreadLocal<SimpleDateFormat> format1 = ThreadLocal.withInitial(new Supplier<SimpleDateFormat>(){
	public SimpleDateFormat get(){
		return new SimpleDateFormat("yyyy-MM-dd HH:mm");
	}
});

private String format1(Date date){
	if(date==null){
		return "-";
	} else {
		return format1.get().format(date);
	}
}

%>
